package com.restfb.example;

import java.util.List;

import com.restfb.DefaultFacebookClient;
import com.restfb.DefaultLegacyFacebookClient;
import com.restfb.LegacyFacebookClient;
import com.restfb.Parameter;

public class Principal 
{
	

		private LegacyFacebookClient facebookClient;
		
		private String accessToken = "2227470867|2.oMz1pvg123VqmwoN5VNmZQ__.3600.1304398800.0-752048690|AdKv3C_db4OLTdU8Y4WK30nEIMQ";
	    
		public static final String IDTOTTO= "72345815262";
		private List<Usuario> misUsuarios;
		private List<Message> misMensajes;
	    public Principal() 
	    {
	    	facebookClient = new DefaultLegacyFacebookClient(accessToken);
	    	darUsuarios();
	    	crearCVSUsuarios();
	    	darPostEnTottoBrand();
	    	crearCVSCampana();
	    	crearCVSUserResponses();
	    	
		}

	    private void crearCVSUserResponses() {
			// TODO Auto-generated method stub
			TareaCreacionCVSUserResponses hw=new TareaCreacionCVSUserResponses(misMensajes);
			hw.execute();
		}

		private void crearCVSCampana() {
			// TODO Auto-generated method stub
	    	TareaCreacionCSVCampana hw=new TareaCreacionCSVCampana(misMensajes);
	    	hw.execute();
		}

		private void crearCVSUsuarios() {
			// TODO Auto-generated method stub
			TareaCreacionCSVUsuarios hw=new TareaCreacionCSVUsuarios(misUsuarios);
			hw.execute();
		}

		private void darUsuarios() 
	    {
	    	Long uid = facebookClient.execute("users.getLoggedInUser", Long.class);

	  	  	DefaultFacebookClient lfc = new DefaultFacebookClient(accessToken);
	  	    
	  	  
	  	  String query =
		        "SELECT uid ,name, pic_big, affiliations,birthday_date, religion,political,email,hometown_location,current_location,sex, relationship_status, music, movies, tv, username,books FROM user " + "WHERE uid IN (SELECT uid2 FROM friend  WHERE uid1=" + uid
		            + ")";

	  	  
	  	  	List<Usuario> usuarios = lfc.executeQuery(query, Usuario.class, Parameter.with("return_ssl_resources", "true"));
	  	  	misUsuarios=usuarios;
	  	  	
	  	  	
	  	    for (Usuario cl : usuarios)
	  	    	System.out.println(cl);
		}
	    
		private void darPostEnTottoBrand()
		{
			Long uid = facebookClient.execute("users.getLoggedInUser", Long.class);

	  	  	DefaultFacebookClient lfc = new DefaultFacebookClient(accessToken);
	  	  	
	  	  String query =" SELECT comments, likes,post_id, actor_id,message,viewer_id FROM stream WHERE source_id="+IDTOTTO;
			
	  	List<Message> messages = lfc.executeQuery(query, Message.class, Parameter.with("return_ssl_resources", "true"));
	  	misMensajes=messages;
	  	for (Message cl : messages)
	  	    	System.out.println(cl);
		}
		
		public static void main(String[] args) 
	    {
			new Principal();
		}
	    
	    

}
